package com.weds.edwx.web;

import com.weds.core.annotation.Logs;
import com.weds.core.base.BaseController;
import com.weds.core.resp.JsonResult;
import com.weds.edwx.entity.DtUserEntity;
import com.weds.edwx.service.DtUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/dtUser")
@Api(value = "人员档案管理",description = "人员档案管理")
public class DtUserController extends BaseController {

    @Autowired
    private DtUserService dtUserService;

    @Value("${weds.scm.join-us-url}")
    private String url;


    @Logs
    @ApiOperation(value = "获取档案页面连接", notes = "获取档案页面连接")
    @RequestMapping(value = "/getUrl" , method = RequestMethod.GET)
    public JsonResult getUrl(){
        return succMsgData(url);
    }

    @Logs
    @ApiOperation(value = "新增人员档案", notes = "新增人员档案")
    @RequestMapping(value = "/insertUser" , method = RequestMethod.POST)
    public JsonResult insertUser(@RequestBody DtUserEntity dtUserEntity){
        if (dtUserEntity.getUserLname() == null || ("").equals(dtUserEntity.getUserLname())) {
            return failMsg("人员姓名为空");
        }
        // 获取人员序号
        Integer userSerial = dtUserService.getUserSerial();
        // 更新人员序号
        userSerial = userSerial + 1;
        dtUserService.updateUserSerial(userSerial);
        // 新增人员 卡 账户
        return succMsg();
    }

}
